package com.bolang.onlycode.demo.quene;

import java.util.concurrent.Exchanger;

public class ExchangeTest {

    public static void main(String[] args) {
        Exchanger exchanger =new Exchanger();
       new Thread(()->{
           String str ="aa1";
           try {
               System.out.println(Thread.currentThread().getName()+"线程名     --------"+exchanger.exchange(str));
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
       },"aa").start();
        new Thread(()->{
            String str ="bb1";
            try {
          System.out.println(Thread.currentThread().getName()+"线程名     --------"+exchanger.exchange(str));
            } catch (Exception e) {
                e.printStackTrace();
            }
        },"bb").start();



    }
}
